package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.activity.douluodalu.config.DouLuoDaLuEventInfo;
import com.yanqu.road.entity.activity.douluodalu.config.DouLuoDaLuRegionInfo;
import com.yanqu.road.entity.activity.douluodalu.enums.eDouLuoDaLuBuffType;
import com.yanqu.road.entity.log.LogDouLuoDaLuExplore;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_EXPLORE_FROM_CROSS,desc = "探索")
public class DouLuoDaLuExploreCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DouLuoDaLuProto.DouLuoDaLuExploreRespMsg respMsg = DouLuoDaLuProto.DouLuoDaLuExploreRespMsg.parseFrom(packet.getBytes());
        if(respMsg.getRet() == 0){
            DouLuoDaLuEventInfo eventInfo = DouLuoDaLuMgr.getConfig().getEventInfo(respMsg.getEventId());
            DouLuoDaLuRegionInfo regionInfo = DouLuoDaLuMgr.getConfig().getRegionInfo(respMsg.getRegionId());
            if(eventInfo != null && regionInfo != null){
                long targetId = respMsg.getEnemyId();
                if(respMsg.getMonsterId() > 0){
                    targetId = respMsg.getMonsterId();
                }
                //日志
                LogDouLuoDaLuExplore log = new LogDouLuoDaLuExplore(DouLuoDaLuMgr.getActivityInfo().getActivityId(), player.getUserId(), respMsg.getTeamId(), respMsg.getRegionId(),
                        eventInfo.getEventId(), eventInfo.getEventType(), respMsg.getEnergy(), regionInfo.getEnergy(), targetId);
                if(respMsg.getBuffList().contains(eDouLuoDaLuBuffType.ENERGY_BUFF.getId())){
                    log.setUseEnergy(0);
                }
                AutoLogMgr.add(log);

            }
            DouLuoDaLuModule douLuoDaLuModule = player.getModule(DouLuoDaLuModule.class);
            douLuoDaLuModule.teamId = respMsg.getTeamId();
            douLuoDaLuModule.regionId = respMsg.getRegionId();
        }
        player.sendPacket(Protocol.U_DOU_LUO_DA_LU_EXPLORE, respMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
